package com.application.mylibrary.base.mvp;

import android.os.Bundle;
import android.support.annotation.Nullable;

import com.application.mylibrary.base.BaseFragment;

/**
 * Created by lixuce on 2019/8/9.
 */
public abstract class BaseMvpFragment <V extends IBaseView, P extends IBasePresenter<V>>  extends BaseFragment {

    private V view;
    private P presenter;

    public abstract V createView();
    public abstract P createPresenter();

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        if(view == null)
            view = createView();
        if(presenter == null)
            presenter = createPresenter();
        if(view != null && presenter != null) {
            this.presenter.attachView(view);
        }
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        if(presenter != null) {
            this.presenter.detachView();
            this.presenter = null;
        }
    }


    public P getPresenter() {
        return presenter;
    }
}
